ABC275 C - Counting Squares
提出
code: python
from collections import defaultdict
d = defaultdict(int)
p = []
for c in range(9):
for r in range(9):
p.append((c+1, r+1))
dis = []
for i in p:
for j in p:
if i == j:
continue
else:
dis.append((i0-j0, i1-j1)) for i in dis:
dw = []
for k, v in d.items():
if v == 1:
continue
else:
dw.append((k, v))
print(dw)
# ((0, -1), 2), ((-1, 0), 2), ((0, 1), 2), ((1, 0), 2), ((-1, 2), 2), ((-2, -1), 2), ((1, -2), 2), ((2, 1), 2) 解答
code: python
import itertools
sharp = set()
for c in range(9):
for r in range(9):
sharp.add((c, r))
ans = 0
for i in itertools.combinations(sharp, 4):
distance = set()
for j1, j2 in itertools.combinations(i, 2):
distance.add((j10-j20)**2 + (j11-j21)**2) # 辺と対角線
if len(distance) == 2:
ans += 1
print(ans)
テーマ
メモ
提出
code: python
from itertools import combinations
from collections import Counter
p = []
for i in range(9):
for j in range(9):
p.append((i+1, j+1))
ans = 0
for i in combinations(p, 4):
l = []
for j in combinations(i, 2):
l.append(abs(j00 - j10) + abs(j01 - j11)) c = Counter(l)
if len(c) == 2:
two = False
four = False
for v in c.values():
if v == 2:
two = True
elif v == 4:
four = True
if two and four:
ans += 1
print(ans)